package banwood.com.xiongfasy.BASE;


import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import banwood.com.xiongfasy.R;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity extends Activity{
	
	private ActionBar actionBar;
	private ImageView back;
	private View view;
	private LayoutInflater inflater;
	Unbinder unbinder;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		 if(getLayoutId()!=0){
			 setContentView(getLayoutId());
			 	injectView();
	            inflater=LayoutInflater.from(this);
	            view=inflater.inflate(R.layout.actionbar,null);
	            back = (ImageView) view.findViewById(R.id.back);
	            actionBar = getActionBar();
	            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
	            actionBar.setDisplayHomeAsUpEnabled(false);
	            //左侧图表点击事件失能
	            actionBar.setHomeButtonEnabled(true);
	            //使左上角图标（系统）是否显示
	            actionBar.setDisplayShowHomeEnabled(false);
	            //显示标题
	            actionBar.setDisplayShowTitleEnabled(false);
	            //显示自定义视图
	            actionBar.setDisplayShowCustomEnabled(true);
	            actionBar.setCustomView(view);
	            back.setOnClickListener(new View.OnClickListener() {
	                @Override
	                public void onClick(View v) {
	                    finish();
	                }
	            });

	        }
	        initView();
	        initData();

	}
	
	 public void settitle(String title) {
	      ( (TextView)(actionBar.getCustomView().findViewById(R.id.title))).setText(title);
	    }
	 
	 public void settitle1(SpannableString styledText) {
	        ((TextView) (actionBar.getCustomView().findViewById(R.id.title)))
	                .setText(styledText);
	    }
	
	 /*
	   * 获取控件
	   * */
	    public <T extends View> T obtainView(int resId){
	        return (T)findViewById(resId);
	    }

	    protected abstract int getLayoutId();

	    protected abstract void initView();

	    protected abstract void initData();

	public void injectView(){
		 unbinder = ButterKnife.bind(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unbinder.unbind();
	}
}
